{
 "metadata": {
  "name": "",
  "signature": "sha256:3fbd75297ea7091391df3b2021105fe79f883d44cae280cbba876c9670ef6e39"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import operator\n",
      "import matplotlib.pyplot as plt\n",
      "%matplotlib inline"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "rd = np.random.randn(100) * 10 \n",
      "x1 = np.linspace(0, 10, 100)\n",
      "y1 = np.random.rand(100) + rd\n",
      "\n",
      "\n",
      "x2 = np.linspace(10, 20, 100)\n",
      "y2 = np.random.rand(100) + rd\n",
      "\n",
      "def plot(x1, y1, x2, y2):\n",
      "    scatter0 = plt.scatter(x1, y1, c='b', marker='o')\n",
      "    scatter1 = plt.scatter(x2, y2, c='r', marker='x')\n",
      "    plt.legend(handles=[scatter0, scatter1], labels=['label0','label1'],loc='best')\n",
      "    \n",
      "plot(x1, y1, x2, y2)\n",
      "plt.show() "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJztnX+QHdV1579nkBTV8MOCEcYKYmYw\nuDAIjIxUJlpYExe2UZxUWKfYhM2Q5ZdLZeygQfFWDFYiTbZqqhZTi0oEsyltcC2OxsG2EgLZjWMg\nYUNctvGOKGF+WSAbjSIVASEjeV0qFknv7B/9WtPT6h+3f9x7T3efT1XXe92v3+vT9733veeec38Q\nM0NRFEVpPwO+DVAURVHcoIKv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Rf9538H\nYD4RLbZtFzPv6z++CeARBE3rKCZlaotfA/AsM78Rf8FXefV5Iwxr9R/fTDjHS7kR0U0AfgPAWF8s\nTsDgO68VZn6DmY8xcw/Af0+5nq/ymgfgtwB8I+0cm+WVogvefl9NE/z/A+ADRHRu3zu8HsBjsXMe\nAxBmtK8D8I9pf4y66McIHwTwMjPfm3LO+8JcAhF9BEHZW62IiOhkIjo1fI4g6fdC7LTHAPxHCvgV\nAIcizU3bpHpePsorQvQ3dCOARxPO+Q6ATxLR6f0Qxif7x6xBRKsB/CGA32TmwynnmHznddsVzfl8\nOuV6Jv9dG3wcwI+ZeW/SizbLK0MX/P2+6s5M294Q9Cp5BUHGf33/2H9G8CcAgIUIQgS7APwQwPsd\n2HQlgmbZjwDs6G+fAvBZAJ/tn/P7AF5E0DvhBwD+jQO73t+/3nP9a4flFbWLAHylX57PA1jp6Hs8\nGYGAvydyzHl5IahwXgdwBEGc9FYEOZ9/APAqgCcBnNE/dyWAP4+895b+72wXgJsd2LULQVw3/I2F\nvdF+GcDfZX3nlu36i/5v50cIxGxJ3K7+/gn/XZt29Y//j/A3FTnXSXll6IK335eOtFUURekITQvp\nKIqiKCVRwVcURekIKviKoigdQQVfURSlI6jgK4qidAQVfEVRlI6ggq8oitIRVPAVRVE6wv8HDNuW\nSm1lY2cAAAAASUVORK5CYII=\n",
       "text": [
        "<matplotlib.figure.Figure at 0x7fe217832128>"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def knn(K, center, data, label):\n",
      "    center = np.tile(center,(data.shape[0],1))\n",
      "    diff = np.sqrt(np.sum((center - data)**2, axis = 1))\n",
      "    #print (diff.shape)\n",
      "    index = diff.argsort()\n",
      "    label_dict = dict()\n",
      "    for i in range(K):\n",
      "        result = label[index[i]]\n",
      "        label_dict[result] = label_dict.get(result, 0) + 1\n",
      "    label_dict = sorted(label_dict.items(), key=operator.itemgetter(1), reverse=True)\n",
      "    return (label_dict[0][0])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x_data = np.hstack((x1,x2))\n",
      "y_data = np.hstack((y1,y2))\n",
      "#print (x_data.shape)\n",
      "data = np.hstack((x_data.reshape(-1,1),y_data.reshape(-1,1)))\n",
      "#print (data.shape)\n",
      "label = [\"A\"]*100 + [\"B\"]*100\n",
      "center = np.array([10, 2])\n",
      "K = 50\n",
      "print (\"The result is: \", knn(K, center, data,label))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The result is:  A\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 22
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}